﻿using System;
using System.Collections.Generic;

//--

namespace IupNET
{
    public class ColorDlg:IupBase
    {
        public ColorDlg()
            : base(Iupc.ColorDlg())
        {

        }


        public int Alpha
        {
            get
            {
                return Convert.StringToInt(GetAttribute("ALPHA"));
            }
            set
            {
                SetAttribute("ALPHA", value.ToString());
            }
        }

        public Color[] ColorTable
        {

            get
            {
                string str = GetAttribute("COLORTABLE");
                if (str == null)
                    return null;
                string[] strs = str.Split(new char[] { ';' });
                List<Color> res = new List<Color>();
                foreach (string s in strs)
                {
                    if (s.Trim() == "")
                        res.Add(Color.Empty);
                    else 
                        res.Add(Convert.StringToColor(s));
                }

                return res.ToArray();
            }
            set
            {
                List<string> strs = new List<string>();
                foreach (Color c in value)
                {
                    if (c != Color.Empty)
                        strs.Add(Convert.ColorToString(c));
                    else
                        strs.Add("");
                    
                    
                }

                string val = string.Join(";", strs.ToArray());
                SetAttribute("COLORTABLE", val);
               
            }
        }

        public Dialog ParentDialog
        {
            get
            {
                return GetHandle(GetAttribute("PARENTDIALOG")) as Dialog;
            }

            set
            {
                SetAttribute("PARENTDIALOG", value.HandleName);
            }
        }


        public bool ShowAlpha
        {
            get
            {
                return GetAttribute("SHOWALPHA") == "YES";
            }
            set
            {
                SetAttribute("SHOWALPHA", value ? "YES" : "NO");

            }
        }

        public bool ShowColorTable
        {
            get
            {
                return GetAttribute("SHOWCOLORTABLE") == "YES";
            }
            set
            {
                SetAttribute("SHOWCOLORTABLE", value ? "YES" : "NO");

            }
        }

        

        public bool Status
        {
            get
            {
                return GetAttribute("STATUS") == "1";
            }
        }

        public string Title
        {
            get
            {
                return GetAttribute("TITLE");
            }
            set
            {
                SetAttribute("TITLE", value);
            }
        }

        public Color Value
        {
            get
            {
                return Convert.StringToColor(GetAttribute("VALUE"));
            }
            set
            {
                SetAttribute("VALUE", Convert.ColorToString(value));
            }
        }

        public void Popup(int x, int y)
        {
            Iupc.Popup(cobject, x, y);
        }

        public EventCallback HelpCB
        {
            get
            {
                return CBHandler.Fetch("HELP_CB");
            }
            set
            {
                CBHandler.Set("HELP_CB", value);
            }
        }

        
    }

    
}
